﻿@using Smartstore.Web.Models.Catalog
@using Smartstore.Web.Models.Cart

@model CartItemPriceModel

@{
    var showPriceSaving = Model.Saving.SavingAmount.HasValue && (Model.ShowRetailPriceSaving || Model.RegularPrice != null);
    var showPrice = !(Model.IsBundlePart && Model.UnitPrice == 0);

    async Task RenderPromoPriceLine(ComparePriceModel priceModel)
    {
        <div sm-if="priceModel != null" class="pd-promoprice-line">
            <span class="pd-promoprice-label">@(priceModel.Label):</span>
            <data asp-for="@priceModel.Price" class="pd-promoprice pl-1">@Html.Raw(priceModel.Price)</data>
            <button sm-if="priceModel.Description.HasValue()"
                    type="button"
                    class="pd-promoprice-tip popover-trigger reset"
                    data-toggle="popover"
                    data-container="body"
                    data-placement="top"
                    data-trigger="focus"
                    data-content="@priceModel.Description"
                    aria-label="@priceModel.Description">
                <i class="fa fa-circle-info" aria-hidden="true"></i>
            </button>
        </div>
    }
}

@* Promo badges *@
<div sm-if="Model.Badges.Count > 0" class="pd-promobadges">
    @foreach (var badge in Model.Badges.OrderBy(x => x.DisplayOrder))
    {
        <span class="badge badge-@badge.Style">@Html.Raw(badge.Label)</span>
    }
</div>

@* Final single unit price *@
<div sm-if="showPrice" class="pd-finalprice" attr-class='(Model.Saving.HasSaving, "pd-finalprice-offer")'>
    <data asp-for="@Model.UnitPrice" class="pd-finalprice-amount">
        @Html.Raw(Model.UnitPrice)
    </data>
    <span sm-if="Model.CountdownText != null" class="pd-offer-countdown">
        @Html.Raw(Model.CountdownText)
    </span>
</div>

@* Compare prices *@
<div sm-if="Model.RegularPrice != null || Model.RetailPrice != null" class="pd-promoprice-group">
    @{
        await RenderPromoPriceLine(Model.RegularPrice);
        await RenderPromoPriceLine(Model.RetailPrice);
    }

    @* You save *@
    <div sm-if="showPriceSaving" class="pd-promoprice-line">
        <span class="pd-promoprice-label">@T("ShoppingCart.ItemYouSave"):</span>
        <span class="pd-promosaving pl-1 d-flex">
            <data asp-for="@Model.Saving.SavingAmount.Value">@Model.Saving.SavingAmount.Value</data>
            <span class="badge badge-danger pd-saving-badge">
                @Html.Raw(T("Products.SavingBadgeLabel", Model.Saving.SavingPercent.ToString("N0")))
            </span>
        </span>
    </div>
</div>

@if (Model.ShippingSurcharge.HasValue)
{
    <data asp-for="@Model.ShippingSurcharge.Value" class="pd-legalinfo">
        @Html.Raw(Model.ShippingSurcharge.Value)
    </data>
}

<div class="pt-2 fs-sm" sm-suppress-if-empty>
    @* Subtotal *@
    <div sm-if="!Model.IsBundlePart && showPrice && Model.UnitPrice != Model.SubTotal" class="pd-subtotal fs-sm">
        <span class="pd-subtotal-label">@T("ShoppingCart.ItemTotal"):</span>
        <data asp-for="@Model.SubTotal" class="pd-subtotal-amount fwm">
            @Html.Raw(Model.SubTotal)
        </data>
    </div>
    @* Pangv *@
    <div sm-if="Model.BasePriceInfo.HasValue()" class="pd-pangv lrm">
        @Html.Raw(LocalizedValue.FixBrackets(Model.BasePriceInfo, WorkContext.WorkingLanguage))
    </div>
</div>